home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / networke / xfirepow.000 / xfirepow / xfirepower-0.84 / client / main.c < prev    next >
C/C++ Source or Header  |  1996-03-16  |  5KB  |  214 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/time.h>
  5. #include <math.h>
  6. #include <pwd.h>
  7. #include <sys/types.h>
  8. #include "Wlib.h"
  9. #include "data.h"
  10. #include "defs.h"
  11. #include "proto.h"
  12. #include "images.h"
  13.  
  14. #define BORDER 1
  15.  
  16. void print_usage()
  17. {
  18.     printf("\
  19. XFirepower client v%d.%02d\n\
  20. Copyright (c) 1995 Joe Rumsey\n\
  21. \n\
  22. Usage:\n\
  23. xfire [options] [server]\n\
  24. Options:\n\
  25. -h <server> (Default esoteric.agron.iastate.edu)\n\
  26. -p <port>   (Default 12592)\n\
  27. -n <name>   (Default guest)\n\
  28. -r <file>   Defaults file (default ~/.firepowerrc)\n\
  29. %s\n\
  30. ", CLIENTVERSION/100, CLIENTVERSION%100,
  31. #ifdef UDP_PROXY
  32.            "  -P <proxy_server> <proxy_port>"
  33. #else
  34.            ""
  35. #endif
  36.            );
  37. }
  38.  
  39. char *getLogin()
  40. {
  41.     struct passwd *pwd;
  42.  
  43.     if(!(pwd = getpwuid(getuid()))) {
  44.         return "Bozo";
  45.     } else {
  46.         return pwd->pw_name;
  47.     }
  48. }
  49.  
  50. int
  51. main(int argc, char **argv)
  52. {
  53.     int ac, i, j, cport=0;
  54.     char *cname = 0, *cserver=0, *deffile = 0;
  55.     int start;
  56.     char *dpyname=0;
  57.  
  58.     for(ac = 1; ac < argc; ac++) {
  59.         if(*argv[ac] == '-') {
  60.             if(strcmp(argv[ac], "-display") == 0 && (ac+1 < argc)) {
  61.                 dpyname = argv[++ac];
  62.             } else if(strcmp(argv[ac], "-h")==0 && (ac+1 < argc)) {
  63.                 cserver = argv[++ac];
  64.             } else if(strcmp(argv[ac], "-p")==0 && (ac+1 < argc)) {
  65.                 cport = atoi(argv[++ac]);
  66.             } else if(strcmp(argv[ac], "-n")==0 && (ac+1 < argc)) {
  67.                 cname = argv[++ac];
  68.             } else if(strcmp(argv[ac], "-r")== 0 && (ac+1 < argc)) {
  69.                 deffile = argv[++ac];
  70. #ifdef UDP_PROXY
  71.             } else if(strcmp(argv[ac], "-P")==0 && (ac+2 < argc)) {
  72.                 proxyServer = argv[++ac];
  73.                 proxyPort = atoi(argv[++ac]);
  74.                 useUdpProxy = 1;
  75. #endif
  76.             } else {
  77.                 print_usage();
  78.                 exit(0);
  79.             }
  80.         } else {
  81.             server = argv[ac];
  82.         }
  83.     }
  84.  
  85.     for(i=0;i<MAXPLAYERS;i++) {
  86.         players[i].p_status = PEMPTY;
  87.         players[i].p_num = i;
  88.         players[i].p_char = (i < 10) ? i+'0' : i-10+'a';
  89.         for(j=0;j<MINESPERPLAYER;j++)
  90.             mines[i*MINESPERPLAYER+j].mi_status = MIEMPTY;
  91.     }
  92.  
  93.     read_defaults(deffile);
  94.  
  95.     callServer(cport ? cport : port, cserver ? cserver : server);
  96.     sendLogin(cname ? cname : name, getLogin());
  97.  
  98.     W_Initialize(dpyname);
  99.     baseWin = W_MakeWindow("XFirepower", 0, 0, WINWIDTH+MAXMAPSIZE*2, WINHEIGHT + 33 * W_Textheight + BORDER*4, 
  100.                            0,"bomb here",0, W_White);
  101.     cwin = W_MakeWindow("combat", 0, 0, WINWIDTH, WINHEIGHT, baseWin, 0, 0, W_White);
  102.     dashwin = W_MakeWindow("dash", 0, WINHEIGHT, 80*W_Textwidth+BORDER, 3*(W_Textheight+2), 
  103.                            baseWin, 0, 1, W_White);
  104.     messwin[MW_JOINED] = W_MakeScrollingWindow("message", 0, WINHEIGHT+BORDER*2+W_Textheight+3*(W_Textheight+2), 
  105.                                                80, 28, baseWin, "xterm", BORDER);
  106.     messwin[MW_INDIV] = W_MakeScrollingWindow("indiv", 0, WINHEIGHT+BORDER*2+W_Textheight+3*(W_Textheight+2),
  107.                                               80, 5, baseWin, "xterm", BORDER);
  108.     messwin[MW_TEAM] = W_MakeScrollingWindow("team", 0, WINHEIGHT+BORDER*2+6*W_Textheight+3*(W_Textheight+2),
  109.                                              80,10, baseWin, "xterm", BORDER);
  110.     messwin[MW_ALL] = W_MakeScrollingWindow("all", 0, WINHEIGHT+BORDER*2+16*W_Textheight+3*(W_Textheight+2),
  111.                                             80,13, baseWin, "xterm", BORDER);
  112.     typewin = W_MakeTextWindow("send", 0, WINHEIGHT+3*(W_Textheight+2)+BORDER, 80, 1, baseWin, "xterm", BORDER);
  113.     playerwin = W_MakeTextWindow("player", 80*W_Textwidth + BORDER*2, WINHEIGHT, 60, 33, baseWin, 0, BORDER);
  114.     mapwin = W_MakeWindow("map", WINWIDTH, 0,
  115.                           80, 80,
  116.                           baseWin, 0, BORDER, W_Grey);
  117.     win3d = W_MakeWindow("threed", 0, 0, 320, 200, 0, 0, 0, W_White);
  118.     W_Buffer(mapwin, 0);
  119.     W_MapWindow(mapwin);
  120.  
  121.     /*
  122.     W_Buffer(win3d, 1);
  123.     W_MapWindow(win3d);
  124.     */
  125.  
  126.     for(i=0;i<MW_MAX;i++)
  127.         W_Buffer(messwin[i], 0);
  128.     W_Buffer(typewin, 0);
  129.     W_Buffer(playerwin, 0);
  130.     W_Buffer(dashwin, 0);
  131.  
  132.     W_MapWindow(baseWin);
  133.     W_MapWindow(cwin);
  134.     if(!splitWindows)
  135.         W_MapWindow(messwin[MW_JOINED]);
  136.     else {
  137.         W_MapWindow(messwin[MW_ALL]);
  138.         W_MapWindow(messwin[MW_TEAM]);
  139.         W_MapWindow(messwin[MW_INDIV]);
  140.     }
  141.  
  142.     W_MapWindow(typewin);
  143.     W_MapWindow(playerwin);
  144.     W_MapWindow(dashwin);
  145.  
  146.     for(i=0;i<MW_MAX;i++)
  147.         W_DefineTextCursor(messwin[i]);
  148.     W_DefineTextCursor(typewin);
  149.  
  150.     W_SetRGB16(W_Green2, 0, 32000, 0);
  151.     W_SetRGB16(W_Blue, 0x7777, 0x7777, 0xffff);
  152.  
  153.     init_terrain();
  154.  
  155.     myTankImg = getImage(I_TANK);
  156.     teamTankImg[0] = getImage(I_BLUETANK);
  157.     teamTankImg[1] = getImage(I_REDTANK);
  158.     expImg = getImage(I_EXPLOSION);
  159.     mineImg = getImage(I_MINE);
  160.     mineExpImg = getImage(I_MEXP);
  161.  
  162.     shellImg = getImage(I_SHELL);
  163.     flagImg[0] = getImage(I_FLAG1);
  164.     flagImg[1] = getImage(I_FLAG2);
  165.  
  166.     W_Flush();
  167.  
  168.     W_ClearWindow(baseWin);
  169.  
  170.     srand(time(0));
  171.  
  172.     inittrigtables();
  173.     start = time(0);
  174.  
  175.     if(read_map()) {
  176.         while(!quit) {
  177.             doServer();
  178.  
  179.             if(me->p_status != POUTFIT) {
  180.                 do_input();
  181.                 do_redraw();
  182.                 if(redrawMotd && W_IsMapped(motdwin))
  183.                     display_motd();
  184.                 do_dash(0);
  185.             } else {
  186.                 do_outfit();
  187.                 if(redrawMotd)
  188.                     display_motd();
  189.             }
  190.         
  191.             if(redrawmap) {
  192.                 redraw_map();
  193.                 redrawmap = 0;
  194.             }
  195.  
  196.             check_playerwin_updates();
  197.             counter++;
  198.         }
  199.     } else {
  200.         printf("Error reading map!\n");
  201.     }
  202.  
  203.     if(time(0)-start > 0) {
  204.         printf("Total frames: %d\n", counter);
  205.         printf("Frames/sec: %f\n", (double)counter/(double)(time(0)-start));
  206.         printf("Total bytes: %d, Bytes/sec: %ld, Bytes/frame: %d\n",
  207.                totalread, totalread/(time(0)-start), totalread/counter);
  208.     }
  209.     W_UnmapWindow(baseWin);
  210.     exit(0);
  211. }
  212.  
  213.  
  214.